﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TracNghiemChonTruong.Class;

namespace TracNghiemChonTruong
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (SessionUtils.FullName == null)
            {
                Response.Redirect("/Index.aspx");
            }

            if (!IsPostBack)
            {
                LoadData1();
                LoadData2();
                LoadData3();

                SessionUtils.ClearMark();
            }
        }
        void LoadData1()
        {
            rpt1.DataSource = QuestionManager.CreateInstant().GetListGroup(1);
            rpt1.DataBind();
        }
        void LoadData2()
        {
            rpt2.DataSource = QuestionManager.CreateInstant().GetListGroup(2);
            rpt2.DataBind();
        }
        void LoadData3()
        {
            rpt3.DataSource = QuestionManager.CreateInstant().GetListGroup(3);
            rpt3.DataBind();
        }

        [System.Web.Services.WebMethod]
        public static void GoToStep2(int markR, int markC, int markE, int markI, int markA, int markS)
        {
            var marks = new Dictionary<string, int>
                                {
                                    {"R", markR},
                                    {"C", markC},
                                    {"A", markA},
                                    {"E", markE},
                                    {"S", markS},
                                    {"I", markI}
                                };

            var sorted = marks.OrderByDescending(x => x.Value);

            SessionUtils.Mark1 = sorted.ElementAt(0).Key;
            SessionUtils.Mark2 = sorted.ElementAt(1).Key;
            SessionUtils.Mark3 = sorted.ElementAt(2).Key;
            SessionUtils.Mark4 = sorted.ElementAt(3).Key;
            SessionUtils.Mark5 = sorted.ElementAt(4).Key;
            SessionUtils.Mark6 = sorted.ElementAt(5).Key;
        }
    }
}